<template>
	<view>
		<view class="upload" @click="uploadFile">
			上传
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			uploadFile() {
				//前端代码
				uni.chooseFile({
					count: 1000,
					success(res) {
						if (res.tempFilePaths.length > 0) {
							res.tempFilePaths.forEach((item, index) => {
								uniCloud.uploadFile({
									filePath: item,
									cloudPath: res.tempFiles[index].name,
									onUploadProgress: function(progressEvent) {
										var percentCompleted = Math.round(
											(progressEvent.loaded * 100) / progressEvent
											.total
										);
									},
									success(uploadResult) {
										uniCloud.callFunction({
											name: "upload_filepath",
											data: {
												type: "quan-tang-shi",
												jsonPath: uploadResult.fileID,
												fileName: res.tempFiles[index].name
											},
											success(call) {
												console.log(call);
											},
											fail(e) {
												console.log(e);
											},
										})

									},
									fail() {},
									complete() {}
								});
							})



						}
					}
				});

			}
		}
	}
</script>

<style>
	.upload {
		width: 100px;
		height: 50px;
		color: white;
		background-color: green;
		border-radius: 25px;
		display: flex;
		justify-content: center;
		align-items: center;

	}
</style>
